varying vec3 diffuseColor;

uniform float clusterCol;
uniform float clusterRow;
uniform float clusterStack;

uniform float COLS;
uniform float ROWS;
//uniform float STACK;
const float STACK = 16.0;
uniform float CLUSTER_COLS;
uniform float CLUSTER_ROWS;
uniform float CLUSTER_STACK;
uniform float CYLINDER_SLICES;

uniform gl_MaterialParameters gl_FrontMaterial;
uniform gl_MaterialParameters gl_BackMaterial;

const float ROW_HEIGHT = 3.0;
const float TALL = 3.0;
const float WIDTH = 2.0*sqrt(3.0);
const float HALF_WIDTH = WIDTH / 2.0;
const float HEX_RADIUS = WIDTH * 2.0;

//const float ScaleFactor = 0.2;
const float C1 = 0.429043;
const float C2 = 0.511664;
const float C3 = 0.743125;
const float C4 = 0.886227;
const float C5 = 0.247708;

const vec3 L00  = vec3( 0.871297,   0.875222,	 0.864470);
const vec3 L1m1 = vec3( 0.175058,   0.245335,	 0.312891);
const vec3 L10  = vec3( 0.034675,   0.036107,	 0.037362);
const vec3 L11  = vec3(-0.004629,  -0.029448,	-0.048028);
const vec3 L2m2 = vec3(-0.120535,  -0.121160,	-0.117507);
const vec3 L2m1 = vec3( 0.003242,   0.003624,	 0.007511);
const vec3 L20  = vec3(-0.028667,  -0.024926,	-0.020998);
const vec3 L21  = vec3(-0.077539,  -0.086245,	-0.091591);
const vec3 L22  = vec3(-0.161784,  -0.191783,	-0.219152);

void main()
{

    float alt = gl_Vertex.y/(3.0*(STACK-1.0));

   gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;

    //spherical harmonics
    float ScaleFactor = alt;//0.4*lightsA.r;
    vec3 tnorm = normalize(gl_NormalMatrix * gl_Normal);

    //vec3 tnorm = gl_Normal;

    diffuseColor = C1 * L22 * (tnorm.x * tnorm.x - tnorm.y * tnorm.y) +
                   C3 * L20 * tnorm.z * tnorm.z +
                   C4 * L00 -
                   C5 * L20 +
                   2.0 * C1 * L2m2 * tnorm.x + tnorm.y +
                   2.0 * C1 * L21  * tnorm.x + tnorm.z +
                   2.0 * C1 * L2m1 * tnorm.y + tnorm.z +
                   2.0 * C2 * L11  * tnorm.x +
                   2.0 * C2 * L1m1 * tnorm.y +
                   2.0 * C2 * L10  * tnorm.z;

   diffuseColor *= ScaleFactor;
  // diffuseColor = vec3(alt);
//diffuseColor.rgb = gl_Normal.rgb;

//diffuseColor = gl_Normal.rgb - gl_Vertex.rgb;
}